package com.das.mechanic_base.adapter.intensivetain;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.processsive.ProcessSiveTempLetBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenSi on 2018/3/13.  tain_detail_fragment
 */
public class X3SiveTainAdapter extends RecyclerView.Adapter<X3SiveTainAdapter.AloneContentHolder> {

    private List<ProcessSiveTempLetBean> mList;

    private Context mContext;

    public X3SiveTainAdapter(Context mContext) {
        this.mContext = mContext;
        mList = new ArrayList<>();
    }

    public void ChangeAloneTitle(List<ProcessSiveTempLetBean> siveReportBeans) {
        this.mList = siveReportBeans;
        notifyDataSetChanged();
    }

    @Override
    public AloneContentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new AloneContentHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_sive_alone_item, parent, false));
    }

    @Override
    public void onBindViewHolder(final AloneContentHolder holder, int position) {
        holder.tv_title.setText(mList.get(position).name + (mList.get(position).standardOrNot ? " " + mContext.getString(R.string.x3_standard_chemical_procedure) : " " + mContext.getString(R.string.x3_custom_record)));
        if(mList.get(position).num == 6){
            holder.iv_point.setImageResource(R.mipmap.x3_alone_finish);
        }else {
            holder.iv_point.setImageResource(R.mipmap.x3_alone_not_finish);
        }
        holder.tv_num.setText(mList.get(position).num + "/" + 6);
        holder.itemView.setOnClickListener(view -> {
            if (iOnClickItem != null) {
                iOnClickItem.iOnItemClickListener(mList.get(position), position);
            }
        });
    }

    private IOnItemClick iOnClickItem;

    public void setIOnClickItem(IOnItemClick iOnClickItem) {
        this.iOnClickItem = iOnClickItem;
    }

    public interface IOnItemClick {
        void iOnItemClickListener(ProcessSiveTempLetBean siveTempLetBean, int position);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class AloneContentHolder extends RecyclerView.ViewHolder {
        private TextView tv_title;
        private ImageView iv_point;
        private TextView tv_num;

        public AloneContentHolder(View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            iv_point = itemView.findViewById(R.id.iv_point);
            tv_num = itemView.findViewById(R.id.tv_num);
        }
    }
}

